import {
	getDataListByCodes
} from '@/services/user.js'
import store from '@/store/index.js'

export const getCodesMap = async (codes) => {
	const resp = await getDataListByCodes({
		codes: codes
	})
}

// 单个获取字典列表
export const getCodeList = async (code) => {
	const resp = await getDataListByCodes({
		codes: code
	})
	if (resp.length) {
		return resp[0].dictionariesDates.map(v => ({
			name: v.dictionariesName,
			value: v.dictionariesValue
		}))
	} else {
		return []
	}

}

export const getCodesToStore = async () => {
	const resp = await getDataListByCodes({
		codes: 'STU_LEVEL,STU_CATEGORY,STU_INDUSTRY,STU_COMPANY_CATEGORY,STU_EDUCATION,STU_EXPERIENCE,STU_TEST_CATEGORY'
	})
	const codes = {}
	resp.forEach((item) => {
		codes[item.code] = item.dictionariesDates.reduce((total, v) => {
			total[v.dictionariesValue] = v.dictionariesName
			return total
		}, {})
	})
	store.state.app.codes = codes
	console.log(resp)
}
export const filterCode = (value, code) => {
	if (value) {
		const codeMap = store.state.app.codes[code]
		const str = codeMap[value] || value
		return str || '--'
	} else {
		return '--'
	}
}
